package com.cloudwise.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/9/28 11:35
 * @description：mybatissqlsession工具类
 * @modified By：
 * @version: 1.0
 */
public class MySqlSessionFactory {
     static SqlSessionFactory sqlSessionFactory;
    static {
        String resource = "mybatis-config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
         sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description:  获取sqlsession
     * @create time: 2021/9/28 11:38
     * @param
     * @return org.apache.ibatis.session.SqlSession
     */
    public static SqlSession getSqlSession(){

        SqlSession sqlSession = sqlSessionFactory.openSession();
        return sqlSession;
    }

}
